feat(isMobilePhone): add support for Croatia (hr-HR) locale#2672
feat(isMobilePhone): add support for Croatia (hr-HR) locale#2672abhu85 wants to merge 1 commit intovalidatorjs:masterfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2672 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 114 114
Lines 2595 2595
Branches 659 659
=========================================
Hits 2595 2595 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Add mobile phone validation for Croatia with support for: - Mobile prefixes: 91, 92, 95, 97, 98, 99 - Format: +385 9X XXXXXXX or 09X XXXXXXX (10 digits local, 12 international) Croatian mobile operators: - 91: T-Mobile (Hrvatski Telekom) - 92, 95: A1 Hrvatska - 97, 98, 99: Various operators (Tele2, etc.) References: - https://en.wikipedia.org/wiki/Telephone_numbers_in_Croatia - ITU-T E.164 numbering plan Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
35c1db9 to
363af92
Compare
There was a problem hiding this comment.
Pull request overview
Adds Croatia (hr-HR) locale support to isMobilePhone by introducing a new validation regex, associated test vectors, and documenting the locale in the README locale list.
Changes:
- Add
hr-HRregex tosrc/lib/isMobilePhone.js. - Add
hr-HRvalid/invalid test cases intest/validators.test.js. - Update README
isMobilePhonelocale list to includehr-HR.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/lib/isMobilePhone.js |
Adds hr-HR locale regex to the phones map. |
test/validators.test.js |
Adds a new hr-HR locale block with valid/invalid samples. |
README.md |
Adds hr-HR to the documented isMobilePhone locale list. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| 'fr-RE': /^(\+?262|0|00262)[67]\d{8}$/, | ||
| 'fr-WF': /^(\+681)?\d{6}$/, | ||
| 'he-IL': /^(\+972|0)([23489]|5[012345689]|77)[1-9]\d{6}$/, | ||
| 'hr-HR': /^(\+?385|0)(91|92|95|97|98|99)\d{7}$/, |
There was a problem hiding this comment.
The new hr-HR regex only matches contiguous digits after the country code/prefix and will reject formats with spaces (e.g. +385 91 1234567 / 091 1234567). The PR description says those spaced formats should be supported, so either update the regex to allow the expected separators (consistent with other locales like cs-CZ, fi-FI, etc.) or adjust the stated supported format.
| '+385911234567', | ||
| '+385921234567', | ||
| '+385951234567', | ||
| '+385971234567', | ||
| '+385981234567', | ||
| '+385991234567', | ||
| '385911234567', | ||
| '0911234567', | ||
| '0921234567', | ||
| '0951234567', | ||
| '0971234567', | ||
| '0981234567', | ||
| '0991234567', | ||
| ], |
There was a problem hiding this comment.
The newly added hr-HR test cases don’t include the space-separated formats called out in the PR description (e.g. +385 9X XXXXXXX / 09X XXXXXXX). If those formats are intended to be supported, add representative valid examples (and potentially a couple invalid spacing variants) so the behavior is covered and won’t regress.
| **isMD5(str)** | check if the string is a MD5 hash.<br/><br/>Please note that you can also use the `isHash(str, 'md5')` function. Keep in mind that MD5 has some collision weaknesses compared to other algorithms (e.g., SHA). | ||
| **isMimeType(str)** | check if the string matches to a valid [MIME type][MIME Type] format. | ||
| **isMobilePhone(str [, locale [, options]])** | check if the string is a mobile phone number,<br/><br/>`locale` is either an array of locales (e.g. `['sk-SK', 'sr-RS']`) OR one of `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-EH', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-PS', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'az-AZ', 'az-LB', 'az-LY', 'be-BY', 'bg-BG', 'bn-BD', 'bs-BA', 'ca-AD', 'cs-CZ', 'da-DK', 'de-AT', 'de-CH', 'de-DE', 'de-LU', 'dv-MV', 'dz-BT', 'el-CY', 'el-GR', 'en-AG', 'en-AI', 'en-AU', 'en-BM', 'en-BS', 'en-BW', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-GY', 'en-HK', 'en-IE', 'en-IN', 'en-JM', 'en-KE', 'en-KI', 'en-KN', 'en-LS', 'en-MO', 'en-MT', 'en-MU', 'en-MW', 'en-NG', 'en-NZ', 'en-PG', 'en-PH', 'en-PK', 'en-RW', 'en-SG', 'en-SL', 'en-SS', 'en-TZ', 'en-UG', 'en-US', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-CU', 'es-DO', 'es-EC', 'es-ES', 'es-GT','es-HN', 'es-MX', 'es-NI', 'es-PA', 'es-PE', 'es-PY', 'es-SV', 'es-UY', 'es-VE', 'et-EE', 'fa-AF', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-BF', 'fr-BJ', 'fr-CD', 'fr-CF', 'fr-DJ', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-PF', 'fr-RE', 'fr-WF', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'ir-IR', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'ky-KG', 'lt-LT', 'mg-MG', 'mn-MN', 'mk-MK', 'ms-MY', 'my-MM', 'mz-MZ', 'nb-NO', 'ne-NP', 'nl-AW', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-AO', 'pt-BR', 'pt-PT', 'ro-Md', 'ro-RO', 'ru-RU', 'si-LK', 'sk-SK', 'sl-SI', 'so-SO', 'sq-AL', 'sr-RS', 'sv-SE', 'tg-TJ', 'th-TH', 'tk-TM', 'tr-TR', 'uk-UA', 'uz-UZ', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', 'zh-TW']` OR defaults to `'any'`. If 'any' or a falsey value is used, function will check if any of the locales match).<br/><br/>`options` is an optional object that can be supplied with the following keys: `strictMode`, if this is set to `true`, the mobile phone number must be supplied with the country code and therefore must start with `+`. Locale list is `validator.isMobilePhoneLocales`. | ||
| **isMobilePhone(str [, locale [, options]])** | check if the string is a mobile phone number,<br/><br/>`locale` is either an array of locales (e.g. `['sk-SK', 'sr-RS']`) OR one of `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-EH', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-PS', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'az-AZ', 'az-LB', 'az-LY', 'be-BY', 'bg-BG', 'bn-BD', 'bs-BA', 'ca-AD', 'cs-CZ', 'da-DK', 'de-AT', 'de-CH', 'de-DE', 'de-LU', 'dv-MV', 'dz-BT', 'el-CY', 'el-GR', 'en-AG', 'en-AI', 'en-AU', 'en-BM', 'en-BS', 'en-BW', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-GY', 'en-HK', 'en-IE', 'en-IN', 'en-JM', 'en-KE', 'en-KI', 'en-KN', 'en-LS', 'en-MO', 'en-MT', 'en-MU', 'en-MW', 'en-NG', 'en-NZ', 'en-PG', 'en-PH', 'en-PK', 'en-RW', 'en-SG', 'en-SL', 'en-SS', 'en-TZ', 'en-UG', 'en-US', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-CU', 'es-DO', 'es-EC', 'es-ES', 'es-GT','es-HN', 'es-MX', 'es-NI', 'es-PA', 'es-PE', 'es-PY', 'es-SV', 'es-UY', 'es-VE', 'et-EE', 'fa-AF', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-BF', 'fr-BJ', 'fr-CD', 'fr-CF', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-PF', 'fr-RE', 'fr-WF', 'ga-IE', 'he-IL', 'hr-HR', 'hu-HU', 'id-ID', 'ir-IR', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'ky-KG', 'lt-LT', 'mg-MG', 'mn-MN', 'mk-MK', 'ms-MY', 'my-MM', 'mz-MZ', 'nb-NO', 'ne-NP', 'nl-AW', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-AO', 'pt-BR', 'pt-PT', 'ro-Md', 'ro-RO', 'ru-RU', 'si-LK', 'sk-SK', 'sl-SI', 'so-SO', 'sq-AL', 'sr-RS', 'sv-SE', 'tg-TJ', 'th-TH', 'tk-TM', 'tr-TR', 'uk-UA', 'uz-UZ', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', 'zh-TW']` OR defaults to `'any'`. If 'any' or a falsey value is used, function will check if any of the locales match).<br/><br/>`options` is an optional object that can be supplied with the following keys: `strictMode`, if this is set to `true`, the mobile phone number must be supplied with the country code and therefore must start with `+`. Locale list is `validator.isMobilePhoneLocales`. |
There was a problem hiding this comment.
The isMobilePhone README locale list still contains incorrect locale casing (am-Am, ro-Md) on this line. These don’t match the actual locale keys (am-AM, ro-MD) exported by validator.isMobilePhoneLocales, which can mislead consumers copying from the docs. Please correct the locale codes while updating this line.
Summary
Add mobile phone validation support for Croatia (hr-HR locale).
Addresses #1761 (Mobile Phone validations - For The First Time Contributors)
Changes
hr-HRregex pattern toisMobilePhone.jssupporting:+385 9X XXXXXXXor09X XXXXXXX(10 digits local, 12 international)Croatian Mobile Operators
Test Plan
References